package com.query;


import com.common.ConstantUtil;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseQueryComplex implements IQueryComplex {

    private Integer start = 1;
    private Integer length = ConstantUtil.PAGE_SIZE;
    private String showType = "0";
    private boolean flag;
    protected Integer sortField;    //排序字段
    protected Integer sortType;     //排序方式

    protected Map<String, Object> params = new HashMap<>();

    protected abstract void init();

    @Override
    public Map<String, Object> params() {
        if (!flag) {
            init();
            String dataOrder = sortOrder();
            if (null != dataOrder && !"".equals(dataOrder.trim())) {
                params.put("sortOrder", dataOrder);
            }
            flag = true;
        }
        return params;
    }

    @Override
    public Integer getStart() {
        if (null == start || start <= 0) {
            start = 1;
        }
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    @Override
    public Integer getLength() {
        if (null == length || length <= 0) {
            length = ConstantUtil.PAGE_SIZE;
        }
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public String getShowType() {
        return showType;
    }

    public void setShowType(String showType) {
        this.showType = showType;
    }

    public Integer getSortField() {
        return sortField;
    }

    public void setSortField(Integer sortField) {
        this.sortField = sortField;
    }

    public Integer getSortType() {
        return sortType;
    }

    public void setSortType(Integer sortType) {
        this.sortType = sortType;
    }
}